package com.sk.bilibili.view.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.ui.StyledPlayerView;
import com.google.gson.Gson;
import com.sk.bilibili.R;
import com.sk.bilibili.bean.Danmu;
import com.sk.bilibili.other.BiliBiliDanmuParser;

import java.net.URI;

import master.flame.danmaku.controller.DrawHandler;
import master.flame.danmaku.danmaku.model.BaseDanmaku;
import master.flame.danmaku.danmaku.model.DanmakuTimer;
import master.flame.danmaku.danmaku.model.android.DanmakuContext;
import master.flame.danmaku.ui.widget.DanmakuSurfaceView;

public class TestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        player = new ExoPlayer.Builder(this).build();
        playerView=findViewById(R.id.player);
        playerView.setPlayer(player);
        playerView.setUseController(false);
    }

    private StyledPlayerView playerView;
    private ExoPlayer player;

    public void send(View view) {
        ImageView show=findViewById(R.id.iv_show);
        Glide.with(this).load("http://82.157.168.147:7000/bilibili/netRes/28605984dd404794.png").into(show);
//        MediaItem mediaItem = MediaItem.fromUri("http://82.157.168.147:7000/bilibili/video/url/6dc315e1df05.flv");
////        player.addMediaItem(mediaItem);
//        mediaItem = MediaItem.fromUri("https://d1--cn-gotcha04.bilivideo.com/live-bvc/657540/live_630455196_44327268_1500.flv?cdn=cn-gotcha04&expires=1642913616&len=0&oi=837431244&pt=web&qn=150&trid=1000f79b174afbda4aa788a978a47e12c3ee&sigparams=cdn,expires,len,oi,pt,qn,trid&sign=74fffd62fd97065a5b44670d38fb7f7e&ptype=0&src=9&sl=1&sk=2935686d6cb9146c7a6a6a0b4e120e250342be3df4dc8310261aab0ce9e21e44&order=1");
//        player.addMediaItem(mediaItem);
//        player.prepare();
//        player.play();



//        EditText input=findViewById(R.id.et_input);
////        input.setFocusable(true);
//        input.requestFocus();
//        InputMethodManager imm = getSystemService(InputMethodManager.class);
//        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
//        Toast.makeText(this, "aaaaaaaaaaaaaaaaaaaaaaa", Toast.LENGTH_SHORT).show();
//        Notification notification = new Notification.Builder(this)
//                .setContentTitle("通知标题")
//                .setContentText("通知内容")
////                .setContentIntent(PendingIntent.getActivity(this,0,
////                        new Intent(this,FlashActivity.class),0))
//                .setSmallIcon(R.mipmap.ic_launcher)
//                .build();
//        NotificationManager manager = getSystemService(NotificationManager.class);
//        manager.notify(1, notification);


    }

//    private WebSocketClient client;
//    private Gson gson;
//
//    public void send(View view) {
//        Danmu danmu = new Danmu();
//        danmu.setContent("TEST");
//        danmu.setMemberId(1);
//        client.send(gson.toJson(danmu));
//    }

//        show1 = findViewById(R.id.vv_show1);
////        show2 = findViewById(R.id.vv_show2);
//        show1.setVideoURI(Uri.parse("https://test-1302807021.cos.ap-nanjing.myqcloud.com/test.flv"));
//        show1.start();
//        new Handler(Looper.getMainLooper()).postDelayed(() -> {
//            show2.setVideoURI(Uri.parse("https://test-1302807021.cos.ap-nanjing.myqcloud.com/test.flv"));
//        },5000);
//        show=findViewById(R.id.dsv_show);
//        show.setCallback(new DrawHandler.Callback() {
//            @Override
//            public void prepared() {
//                show.start();
//            }
//            @Override
//            public void updateTimer(DanmakuTimer timer) {
//            }
//            @Override
//            public void danmakuShown(BaseDanmaku danmaku) {
//            }
//            @Override
//            public void drawingFinished() {
//            }
//        });
//        context = DanmakuContext.create();
//        show.enableDanmakuDrawingCache(true);
//        show.prepare(new BiliBiliDanmuParser(),context);
//        handler.sendEmptyMessageDelayed(2233,1000);
//    }

//    private DanmakuContext context;
//
//    private Handler handler=new Handler(Looper.getMainLooper()){
//        @Override
//        public void handleMessage(@NonNull Message msg) {
//            handler.sendEmptyMessageDelayed(2233,1000);
//            BaseDanmaku danmaku = context.mDanmakuFactory.createDanmaku(6);
//            danmaku.text="adasasas";
//            danmaku.textSize=30;
//            danmaku.textColor= Color.RED;
//            danmaku.time=show.getCurrentTime();
//            show.addDanmaku(danmaku);
//            Log.e("TEST","aaaaaaaaaaaaaaaaaa");
//        }
//    };
//
//    private VideoView show1;
//    private DanmakuSurfaceView show;
//    private VideoView show2;
//    private boolean play=true;

//    @Override
//    public boolean onKeyDown(int keyCode, KeyEvent event) {
//        if(keyCode==KeyEvent.KEYCODE_VOLUME_DOWN){
//            play=!play;
//            if(play){
//                show1.start();
//                show2.pause();
//            }else {
//                show1.pause();
//                show2.start();
//            }
//            return true;
//        }
//        return super.onKeyDown(keyCode, event);
//    }

}